package com.flynn.rock.model.dto.system;

import com.flynn.rock.enums.system.UserAccountStatus;
import com.flynn.rock.enums.system.UserAccountType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserAccountDto implements UserDetails {

    private Long userId;

    private String account;

    private String password;

    private UserAccountType accountType;

    private UserAccountStatus accountStatus;

    private List<AuthorityDto> authorities;

    private List<RoleDto> roles;

    private UserDto user;

    @Override
    public String getUsername() {
        return account;
    }

    @Override
    public boolean isAccountNonExpired() {
        return !UserAccountStatus.EXPIRED.equals(accountStatus);
    }

    @Override
    public boolean isAccountNonLocked() {
        return !UserAccountStatus.LOCKED.equals(accountStatus);
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return Boolean.TRUE;
    }

    @Override
    public boolean isEnabled() {
        return UserAccountStatus.NORMAL.equals(accountStatus);
    }
}
